using Holoville.HOTween;
using Holoville.HOTween.Core;
using I2.Loc;
using UnityEngine;

public class MissionNote : MonoBehaviour
{
	[SerializeField]
	private UILabel note;

	[SerializeField]
	private UIWidget widget;

	private Vector3 startNodePosition;

	private bool showingText;

	public void Awake()
	{
		startNodePosition = note.transform.localPosition;
		base.gameObject.SetActive(false);
		widget.alpha = 0f;
	}

	public void Show()
	{
		HOTween.Kill(widget);
		base.gameObject.SetActive(true);
		HOTween.To(widget, 0.2f, new TweenParms().Prop("alpha", 1).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			ShowNoteText();
		}));
	}

	public void Hide()
	{
		HOTween.Kill(widget);
		HideNoteText();
		HOTween.To(widget, 0.2f, new TweenParms().Prop("alpha", 0).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			base.gameObject.SetActive(false);
		}));
	}

	public void OnClick()
	{
		if (!showingText)
		{
			ShowNoteText();
		}
		else
		{
			HideNoteText();
		}
	}

	public void ShowNoteText(string text)
	{
		note.alpha = 0f;
		note.transform.localScale = Vector3.zero;
		note.text = text;
		note.transform.localPosition = Vector3.zero;
		showingText = true;
		HOTween.Kill(note);
		HOTween.Kill(note.transform);
		HOTween.To(note.transform, 0.2f, new TweenParms().Prop("localScale", Vector3.one));
		HOTween.To(note.transform, 0.2f, new TweenParms().Prop("localPosition", startNodePosition));
		HOTween.To(note, 0.2f, new TweenParms().Prop("alpha", 1));
		CancelInvoke("HideNoteText");
		Invoke("HideNoteText", 4f);
	}

	private void ShowNoteText()
	{
		string text = string.Empty;
		if (ManagerMissions.currMission.numCurStep < ManagerMissions.currMission.listTargetParams.Count)
		{
			text = ManagerMissions.currMission.listTargetParams[ManagerMissions.currMission.numCurStep].target.startMessageTerm;
		}
		if (text != string.Empty)
		{
			ShowNoteText(ScriptLocalization.Get("new_Missions/" + text));
		}
		else
		{
			ShowNoteText(ManagerMissions.currMission.title);
		}
	}

	private void HideNoteText()
	{
		CancelInvoke("HideNoteText");
		showingText = false;
		HOTween.Kill(note);
		HOTween.Kill(note.transform);
		HOTween.To(note.transform, 0.5f, new TweenParms().Prop("localScale", Vector3.zero));
		HOTween.To(note.transform, 0.5f, new TweenParms().Prop("localPosition", Vector3.zero));
		HOTween.To(note, 0.3f, new TweenParms().Prop("alpha", 0));
	}
}
